package com.kevin.designpattern.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * 具体的主题角色对象
 */
public class SubscriptionSubject implements Subject {

    private List<Observer> observerList = new ArrayList<>();

    @Override
    public void attach(Observer observer) {
        observerList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        observerList.remove(observer);
    }

    @Override
    public void notify(String message) {
        // 遍历集合
        for (Observer observer : observerList) {
            // 调用观察者对象中的更新方法
            observer.update(message);
        }
    }
}
